package cn.lcsjsxy.yxz.keywords.static_;

public class apply {

    public static void main(String[] args) {

        //  static关键字的应用
        //

        Circle c1 = new Circle();
        Circle c2 = new Circle();

        Circle c3 = new Circle(666.666);

        System.out.println("c1的id: " + c1.getId());
        System.out.println("c2的id: " + c2.getId());

        System.out.println("c3的id: " + c3.getId());

        System.out.println("创建的个数: " + Circle.getTotal());
    }
}

class Circle{

    private double radius;
    private int id;     //自动赋值

    public Circle(double radius){
        this.radius = radius;
        id = init++;
        total++;
        //或
//        this();       //  *********
//        this.radius = radius;
    }

    public Circle(){
        id = init++;
        total++;
    }

    private static int total;               //记录创建圆的个数
    private static int init = 1001;     //static声明的属性被所有对象所共享

    public double findArea(){
        return 3.14 * radius * radius;
    }

    //

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public double getRadius() {
        return radius;
    }
    public void setRadius(double radius) {
        this.radius = radius;
    }

    //total
    public static int getTotal() {
        return total;
    }

    public static void setTotal(int total) {
        Circle.total = total;
    }
}